Cleaned up the code, correct function names and with extra tests and function comments.
Updated the README.md to show how to use as a library