Fixed issues reported by tads in pr 566