Updated code and refactored