implemented tail function