Added validation of parameters. Combined setBegin and setEnd methods to setBeginAndEnd