Refactored the procedural code.