Fixed a logical fallacy in the query_mediator (it was triggering CYSLE_FINISHED while the cycle was still running); and added more to the error handling