pieced more code together, added some new functions and loops