added optional offset feature and more test cases