Fixed a couple of nasty bugs