refactor code to make it a little more readable