Refactor some old code