ported to mongodb, code still needs clean up