split processimage into appropriate functions