working version. with bug, a fix on NULL_OFFSET