Refactored to remove deprecation warnings