Reorder code to make it more readable