Refactoring done. Code styling and commenting.