add tail funtion
add couple auxiliary functions