move this function out the if