added some comments and refactored some things to try to clear up how some stuff works