added resetting of task references when queue is empty + code clean up