added check for offset, fixes bug