moved around code to make main class easier to read