cleaned unused variables and modified the functions accordingly