updated for new api, approx. 10x faster