Added some optimizations, see #3.