rewrite with a simpler api