Complete refactoring and additions