A lot of changes and refactoring