Bugfix at the subwire:setup task

It will crash now if something couldn't be saved
Bugfix at user.login_status_by_time

It crashs right after first login after database setup since last_activity is nil then.
Additionally I did some refactorings to improve performance and readability.