Rearranging code, removed old code