tidied up offset calculation in main.c