cleaning up code and fixing bugs in aggregate_portfolio