Refactored to beautify the code