restructure the code to make more sense