tested and working, but lots of printfs still need removed