More fixes and tests. Also starting some optimizations