Refactored according to review #2