Bugs rebased

supersedes #535 
this is just a rebased version of it

I'm merging as soon as TravisCI shows green