Am I reading this wrong, or is this function just a really complicated if statement?