generic tail implemetation done