Remove an unneeded nexted if to eliminate some duplicate code