work done for genralizing the code to functions depending on the inputs