Refactored code a little bit.