Added error handling, heading replacement js