Okay TUO here is my solution, sorry for the two extra global variables but there were some really funky issues