Added automatic password rehashing, minor refactoring