cleaned up code for clip image