Fixing null reference problem