A implementation for heads and tails