refactor User code and add tests