added option for an image priority and cleaned up code