use function parameters, simplify code