Added upgrade target and sorted out some dependencies