reorganized a couple functions, better modularity