function could be called when pointer was NULL. fixed