added more error checks and updated doc