Minor refactoring and small changes