Optimize apply_slack for size and speed