refactor stack offset code

More refactoring of stack offset code