Major refactoring for consistency