Major code cleaning in build_image