More refactoring and also more comments are added/corrected.