Minor refactoring for better API