fix error when the request_stack is empty

plus cleanup