refactor code to be a bit more readable