Missing return statements added, otherwise NULL pointer dereferencing.