add some util functions, and clean interface a bit