delete unnecessary if statement and optional parameters. algorothm not changed