fixed the 'offset' bug
fixed the NULL pointer bug