modified the function: added parameters. moved function location