fixed documentation infinite loop, added check for canvas existance