Fix some issues pointed out in @metadave's PR review