refactor to be less ugly