added Result class, smart pointers, lots of refactoring