fix some hideous bugs