diff --git a/src/main/java/NTNU/IDATT1002/controllers/Search.java b/src/main/java/NTNU/IDATT1002/controllers/Search.java
index dfec42a525775b14d4d1ddbb085ad22636650071..c64c9813dc5c2e2a789564a0ec7237576aabb432 100644
--- a/src/main/java/NTNU/IDATT1002/controllers/Search.java
+++ b/src/main/java/NTNU/IDATT1002/controllers/Search.java
@@ -85,6 +85,7 @@ public class Search implements Initializable {
             pane.setPrefHeight(300);
 
             ImageView imageView = new ImageView();
+            imageView.setId(String.valueOf(images.get(i).getId()));
             imageView.setImage(ImageUtil.convertToFXImage(images.get(i)));
             imageView.setFitHeight(300);
             imageView.setFitWidth(500);
@@ -234,15 +235,10 @@ public class Search implements Initializable {
      * @throws IOException
      */
     public void switchToPicture(MouseEvent mouseEvent) throws IOException {
-        boolean imageIdFound = false;
         long imageId = 0;
         Node node = (Node) mouseEvent.getSource();
-        while (!imageIdFound){
-            if (node.getId() != null){
-                imageId = Long.parseLong(node.getId());
-                imageIdFound = true;
-            }
-            node = node.getParent();
+        if (node.getId() != null){
+            imageId = Long.parseLong(node.getId());
         }
 
         if (imageId != 0) {