added a slew of features and some optimizations