Refactored according to code_review notes