Various optimizations and bugfixes

ECC has been fixed