Some code refactoring and indentation fixes.