some bug fixes, changed begin/end to be inclusive bounds