Refactoring to fix failures