fix crash and object declaration sorting