Refactors code, adds tests
Finishes sign in