Calculate offset correctly.

I am a terrible programmer, as you can see.