re-factored portfolio process code