Fixes #1029

This is a straight port of the LESS. I'm sure we could improve on this.