Optimisations

I inadvertently merged #4. This has one new commit, and please review the commits/comments in #4 as well