Fix bugs reported by Juha Riihimäki <juha.riihimaki@nokia.com>: