refactor user lookup to use mdl functions; adds tests, moves things around a little