Some bug fixes

see commit note