move if clause to method