Add comments and small refactoring.