Merged everything into here. Now need to clean up and write tests.