Adding Kyle's two bugfixes
358786a5dcb89cab3d7fc105746be134c2c4d9c8
c043af984a91bab411ee930c4c0066ed7828c029