refactor signin code