Updated safe mode to prevent XSS

Fixed tabbing, added unit more test cases.