got ForiegnFunc (static functions) working, plus some minor refactorings.