Refactor, but still seems to give late output