added more checks if an image was loaded before calculations