refactoring of code to be purrteh