use Object.keys(..) instead of hasOwnProperty
add option to sort keys