Fixed 4 issues (please see commit comments).