fixing a couple of corner cases that were causing crashes