Add stack validation function.