Refactored code, identified some problems.