Added tests and fixed portfolio bug some more

I think I finally got rid of the portfolio bug where empty shells were
being made. I also added some tests.