Refactored and cleaned code.