use filter instead of if statement