Some code refactoring and bug fixes