More porting of stuff from leveldb.
Starting to implement actual logic for database itself