added all the code, got it working under Clang