optimized core: fixed inlining, added tests.