fixed an error where offset would be bigger then total