added final alert. Function now works properly