put cap check condition inside function