Refactoring and speed boosting