bugfix: Fixed NPEs discovered in BugSense

https://www.bugsense.com/dashboard/project/ad73db70#error/97976122
https://www.bugsense.com/dashboard/project/ad73db70#error/97551051
https://www.bugsense.com/dashboard/project/ad73db70#error/97340424
https://www.bugsense.com/dashboard/project/ad73db70#error/97976122
https://www.bugsense.com/dashboard/project/ad73db70#error/97340424