Refactor code to be more consistent