rearranging code to make it more readible