improved implementation and API