A minor if/elif optimisation suggested by @robvdl