Polished code for stack parsing,