You use typeoftrial in search_trial but that routine also appears in search_practice_loop. Is it set in condition_file as well as in master_trials.
Also, you have routine_selector as a JS only code component. I would recommend that you change it to Auto and write the code in Python.