photos upload code factoring