Code refactoring and bug fixing.