added offX and offY calculation