We all have them — bad habits that we wish we didn’t have but feel pessimistic about changing. Maybe you know you really have to spend less time on Facebook or playing online games. Or perhaps you’ve tried a dozen times to quit smoking. Or maybe even thinking about getting more exercise makes you feel too tired to start. Whatever habit you’re trying to break, somehow you haven’t found the key to success.

Search no more. Bad habits can be broken. Really. Here are 7 tips from the researchers who research such things:

1. Cut yourself some slack. Habits are hard to change because, well, they’re habits. There’s a reason why they are hard to break. We actually need most of the habits we have. We go through most of our days engaging in good habits, routines and activities. If we didn’t, everything we did every day would be something we’d have to think about. Instead, we’re wired to learn and put in place activities that sustain us without giving it a moment’s thought.

From the time you stumble into the bathroom in the morning to wash your face to your drive to work where you have a “habit” of following traffic rules, to your routines as you go through your workday to kicking off your shoes when you get back to the house, you are on autopilot a fair amount of the time. That frees your mind and your energy for new situations and new problems that require new decisions, creativity and actions. Unfortunately, the brain really doesn’t discriminate between the bad habits and the good ones. Once a routine is sorted into the “automatic” category, it’s hard to get it back out.

2. Identify the underlying cause. All habits have a function. The habit of brushing your teeth every morning prevents trips to the dentist. The habit of checking your email first thing at work helps you organize your day. Bad habits are no different. They too have a function.

Mindless eating can be a way to comfort yourself when you’re feeling down. Cruising the Internet for hours might be a way you avoid interacting with your partner or kids. Smoking (in addition to being just plain addictive) may be a way to take time out to pause and think. Drinking too much may be the only way you know how to be social. If you want to break the habit, you have to come to grips with whatever function the bad habit is serving.

3. Deal with the real problem. Sometimes dealing is relatively easy. If snacking on junk food all afternoon is a compensation for not eating lunch, it’s obvious that the function of eating whatever is in the vending machine is to satisfy hunger. Your “habit” is telling you that you really do need to stop and take the 15 minutes to have lunch. But if your time on video games is your way to stay out of fights with your partner, it may be painful to face how dysfunctional your relationship has in fact become.

Even if it makes you feel guilty and bad about yourself for having a bad habit, you are not likely to stop it unless you come up with another way to deal with its function. Something positive has to be put in its place. Positive can mean pleasant — like eating that lunch instead of skipping it to forage in the vending machine later. Positive can also be painful but important — like dealing with your feelings instead of stuffing them down with food, or getting into therapy with your partner instead of numbing your problems away with video games or alcohol or weed.

4. Write it down. There’s something about committing a promise to paper that makes that promise more real. Researchers have found that just writing out a goal and keeping it handy to look at every day (or as many times as day as you need to) can help you stay on track. So write down your promise to yourself and read it before every meal and at bedtime. That’s a prescription that has no side effects and is likely to help.

5. Get yourself a buddy. There’s a reason that many recovery programs include group meetings and individual sponsors or therapists. Being accountable to others is a powerful incentive to keep on keeping on. By both giving and receiving support, you keep the goal in focus. Working with an individual sponsor or counselor can help you deal with the basis of your bad habit and find positive, healthy ways to take care of yourself instead. Being accountable to a friend (in person or virtual) helps you just stay on track.

6. Give yourself enough time. Conventional wisdom is that it takes 28 days to get free of a bad habit. Unfortunately, that notion is just plain wrong. Bad habits are hard to break because they are Habits (with a capital H). Remember: your brain has put your bad habit in the “automatic” category. Once there, it’s difficult to shake it free.

Yes, some people can get a good jumpstart in 28 days. But current research shows that most of us need about three months to substitute a new behavior for a bad habit. Some people need longer. Some people need to find a gentle but powerful way to stick with the project for the rest of their lives. It depends on the habit, your personality, your level of stress, and the supports you have in place.

7. Allow for slips. You won’t be perfect. Almost everyone slips up. It’s only human. But it’s not a reason to give up. A slip provides you with information. It tells you what kinds of stressors push you off your good intentions. It tells you what you might need to change in order to stay on track. Think hard about why you slipped and get back on board. Tomorrow is another day.