use LESSER and GREATER to simplify the head and tail function