Re-factored image code