Some stack related bug fixes