Eric Ries on when you should refactor and when you should not:

Here’s a company I met with recently. They have a product that has a moderate number of customers [...] The engineering team has decided it’s reached a breaking point, and is taking several weeks to bring it [code] up to modern standards, including unit tests, getting started with continuous integration, and a new MVC architecture. Doesn't that sound good? [...] I asked, "how much money does the company have left?" And it was this answer that really floored me. They only have enough money to last another three months.

It may sounds obvious or even make you smile, but it happens more than you think. Lots of developers fall into the trap of refactoring and think this is a priority.

Most of the time, it's not. The priority is to not go out of business by missing your deadline.

So, it's really important you ask yourself what matters most before doing it and focus on changes that benefits the product and the customer.

Everything else can come later.