changed if statement to faster solution