Refactor Duality exceptions
Fix foreach in Server