Fixed a couple of longstanding bugs