Changed: refactoring and utility functions