Refactor to using flux