code is below comments, makes more sense at the bottom