Optimizations, bug fixes, initial work for handling duplicate keys in btree