Fix gross nested conditions

Much better implementation I think