Bug fixes according to Eiriks comments