This is a bit obfuscated but seems a bit nicer than having a massive if/else chain.