added functions for sorting attributes and rebuilding element as html