Refactory of cc function