Refactored and fixed ambiguous code, commented code.