Fix #269

Shorten most primitives where possible. Also optimize some edge cases.
Merge pull request #325 from rvanvelzen/fix-269

Fix #269