Most of stuff implemented, but no optimizations done and may be buggy.