sort elements for completion
fixed error type while completion