Refactoring and improved comments.