Some refactoring

* move code from Clojure to C
* caching
* renaming