Heavily refactored, major changes