Fix various bugs reported by betterman