Lots of fixes done together with Paul