Add some checks to prevent JSON error in console