Fixed a bug using some horrible code