These 2 ifs can probably be consolidated into 1