working better, but sometimes null pointer