fix exception raising bugs and add offset handling feature