Refactoring and some code cleaned