Refactoring some things and modularizing password logic. Fixes #1