Oh, I'm so sorry to hear he passed. :(
You did everything you could for him... and I'm sure he knew it. He even appreciated the cave you got him. I sure that made him feel secure.
Since we didn't get a chance to full diagnose him and we don't know exactly what happened, I would highly reccomend draining the 5 gallon tank and sanitizing all contents (and throwing away the filteration material).
Here is a thread on sanitizing: http://www.bettafish.com/showthread....ght=sanitizing
There are some breeders on this board who always have bettas that are 'ready to go'... When you are ready to welcome another betta into your life, please check with them. People on this board care about the fry they raise, and you'll know they had a healthy start in life before they came to live with you.
Take care, and know you made your little buddy as comfortable as you could.