Refactoring and bug fixing.