Major refactoring and updates