Still working on refactoring, but haven't finished yet.