Bit hard to parse, might want to split this out a bit.