placed everything into the function for proper updates