Added try-except in process_q() function