bug fixes and null pointer catching