Add error handling in stack