How does having a treasury work? We've always just divvied up the loot then and there, sometimes with the agreement that any proceeds from a sale will be divvied up between the person who wanted it and the person who had the carrying capacity.
One player (almost always ends up being me in any game I play in) records everything that's found on an adventure. If something's useful while still in the field (like, say, a magic weapon in a party that doesn't otherwise have any) then someone will use it, on the understanding that it still belongs to the party.
Once back in town everything - including magic items - is evaluated into a monetary value, which is then divided down into individual PC shares. (e.g. if a 5-character party come back with 50K worth of treasure then each character's* share value is 10,000) With this, any magic items in the treasury are open to claim, with whatever you end up with counting as part of your share. (so, if my share's 10000 and I claim a +2 sword worth 3500 then I'll get that and 6500 coin)
* - amended if one or more characters weren't in for the whole adventure, which happens very frequently IME.
If two or more characters claim the same item it's usually settled by roll-off. Unclaimed items are sold. If a single item is worth more than a share then either some loaning and borrowing takes place so someone can claim it, or a consortium of two or more characters go in jointly on it. Rarely, an item might be considered so useful to the party (or is so costly that nobody can afford it!) that it's kept back as a party possession and in effect carried forward to the next treasury; thugh people don't often like doing this as it reduces the current treasury's value.
We have a spreadsheet that does the mathmology for us, the sometimes-tedious bit is the data entry.
Why do we do it this way? Mostly so everyone gets - and can rely on getting - an even share. We've occasionally tried other methods over the years, which have quickly resulted in a rather large wealth disparity between characters.
Dividing it on the fly such as you do would risk such, particularly if the items found happen to favour one class over another (e.g. in raiding a wizard's lair you find gobs of useful stuff for the wizard types but the warriors come away with nothing).