fixed issue with empty objects and doing stuff in wrong order