Updated patch per feedback from @pomeh