fixed recursive bug, had no stop condition