fixed some "null" and "next" issues