port from https://gitorious.org/mdb