refactor functions and add username