refactor runApState

Split runApState into a runApState0 wrapper and a runApState worker
refactor runApState

Inline runApState0 worker.
simplify arithmetic
cleanup: rename runApState to aptyMiddle

also rename arguments and update comment