Got rid of deep if/else nesting