Moved and refactored code