Updated the program with functions