refactor the fromValue function