refactoring: remove duplicated code for logging in