Fixing js errors and validating when data is empty