reading through code. made some minor changes for efficiency and whatnot.