Bug fixing and refactoring.