DB and filesystem optimizations, many bug fixes