Bug fix for http://pastebin.com/T05fCRWA