Added tail, made function signatures more accurate