fix s2w and adjust optimizations