straightened out code