Complete rewrite to new API