Fixed some nasty code