Major refactoring done.