Code mostly fixed