moved log before return