Added more comments / refactored code