Refactored code. Comments