Fixes merge conflicts with pull request #182

I'd like someone to review this so as to ensure that there are no unexpected bugs arising from the changes. Also @verhagen could you have a look and check that I haven't removed any of your intended changes while I was fixing the conflicts. Alternatively @verhagen can fix the conflicts in his branch so that #182 can be merged and this pull request discarded as it only reflects 1 commit from me and not the 9 from @verhagen