Result class and small refactoring