fixed lots of bugs with loops, switched to definitions for whole process, added new definitions