Added some comments and implemented tail