Major updates and refactoring