Fixed bugs. Refactored code.