Improve speed and several fixes