Added better error checking, escape html