fix left and right direction to apply pattern to solenoids. Also simplify code