added some comments, refactored some stuff & fixed indenting