Added cleanup and clear queue function