add safe check and formatting js