Fixed a rather nasty bug