changed controller common functions to a Image service