updated to fix bugs, change function names, add offset param