Refactor PackObject, LooseObject

Fix issues in #878 

@devoncarew PTAL thanks.