Fixed #412 - Prevent potential NPE with mode stack