fixed all optimization issues, still buggy with transition phase but 2/3 fully functional