Refactoring + comments added.