Added some comments and name refactorings for clarity