optimization

tried rewriting critical functions in C (unsuccesfully)
more optimization