Automatic code extraction