Refactoring, and major changes along with testing