some slight optimizations, #32, #13 and #11