tail refactored and made mutch better