Refactored, added test, updated doc and demo