Added optional stack height checks.