added generic constructor that supports sorting