Improved updated funcion