function codes and comments added