refactoring API and adding test - Fixed #34