Random fixes and improvements

See commit messages for explanation what was changed.