added better comments
slight refactoring and commenting