bug fixes and simplicfications
sort keys when printing json