sort object keys by ref dependencies. Closes #260