Refactoring. All the code has been commented