Constify cursed_p()
Refactor, clean up logic and fix bugs in borg_item_analyze()