It looks like your if tests here might let the code below run in AH_INIT state.  Probably not what you wanted.