sorting fields
some bugs fixed