move a lot of the external functions to private functions which mutate the internal state