code works but refactorable