Refactored cpp interface and added tests