Credit to Information Mosaic for bugfix.