refactor state to be a record