Refactored code to minimal test case