Small refactoring and more comments to the code.