Major refactoring and adding features