Completed my version of the code needed for friend's assignment