Refactor some code for easier readability