Fixed a bug. Thanks to shadowm for reporting