Added some comments and double checked logic