Refactoring and adding some minor stuff