fixed cleaning function