Added check if end of stack