some possibly unnecessary micro-optimizations; also add more doc-tests