Refactored some code