rearrange the code to make it more logical