Added support for text and date elements
Reorganized code so that the order of elements matches the spec