Cleaned up code and imports, and reorganized a little