refactored a few functions from Project 2