minor refactor of the API so its a bit cleaner for #93 and improved the test case and code a little