Fix bug	that occurs when there are few items
Improved api and added documentation and tests