Improved API and added some tests