refactoring the code so it's neat