refactor by grouping related functions