Fixed getElementOffset method