Refactored based on rewview comments