major update and refactoring