Added in function definition, comments, and checks