Much refactored