refactored code a little.