updated doc
refactored and added tests