now each function uses its parameters instead of global variables