adapted to new api and cleaned things up