Refactor put image function's redirect loop

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>