Refactored code for maximum neatness.