There are a lot of conditionals here. Can we simplify this in any way?