changed do-whiles to whiles to fix notify() bug, made notification conditional