fixes several issues: #630, #631, #632