Refactored according to review