refactored and wrote a class to expose the public api
updated doc