Refactored the code to match my style.