Fixed imbalanced stack related errors