refactored, reindented, and moved some stuff around to make my life easier