updated version of the file with more readiable code