restructured and fixed infinate loop in addtoq