Optimizations; kudos to @marktucker for looking over the lib