Refactored fix for previous commit