I'll look at adding some logging here and joining up some of the if statements.