Flattened if/then nests, removed unnecessary int casts