extensions: Some code refactoring