Legalism is a way of thinking and it's a trap. When a legalist discovers their bondage to legalism the temptation is to come up with a plan or set of rules to get ourselves out of legalism...which is a legalistic way of dealing with it and will only reinforce that bondage. We love programs, tricks, and plans that ultimately focus on how we are to deal with our shortcomings.
Such way of thinking marginalizes Jesus reducing Him to a God that can only help us once we help ourselves. Now here's the beautiful thing. Maybe this resonates with you and in you is a strong desire to stop. That's great. But don't foolishly in that desire try and fix it yourself and reinforce that bondage (Gal. 3:3, 4:9, 5:1). Scripture says if you'll acknowledge your sin before God, He will meet you there and Himself walk you out (1 John 1:9). Trust Him with your struggle to trust Him (Mark 9:24). Let Him do what only He can do anyways (Rom. 8:3, Matt. 1:21). Peter was a legalist and it wasn't Peter who solved that way of thinking (Luke 22:31). We begun by trusting Him, let's continue likewise (Gal. 3:2).