fixed some mongo compilation errors
added buffer to reduce number of system (read) calls