Nit: seems like this could be turned into an else-if so this whole chain of conditions have the same indent level