Reorganize functions to make the API easier to follow