Reorganized the code to be cleaner and more meta.