write tests and do actual TDD before refactoring better yet use hypothesis and do some property driven testing