add tests, fix small bug with negative offset