Added toArray to sort expressions and some restricturing of tests

Change-Id: I81f07cdefe433890d41f5d7c39085fbce05bc9fc