code optimization and queue cleaning