Performance optimizations

This PR _tries_ to reduce method calls and object allocations.

See https://gist.github.com/splattael/5404417 for some benchmarks.
See 44c26fa967846ad4daf9bf990b591504d299e0d1 for more info