Optimized RWSEM algorithm