Added some comments and eliminated a function