Submitted by: Tor Egge <Tor.Egge@idt.ntnu.no>
Bug fixes.
Closes PR #2171. Submitted by: Tor Egge <tegge@idt.ntnu.no>