refactor to make it a bit tidier