Fix password reset
Minor tweaks
More code reorganisation