Try to do most of your refactoring before you start coding.