Replaced a lot of nasty offset code