I am planning on refactoring this code in a separate PR.