Null object exception

Added null check to avoid unhandled exception crashing VS.