reorganize functions for readability and clarity