Syntax fixes

This is a cherry-pick of the work by @charrius and supersedes #6, #7 and #8