Tidied up dependency handling, improved test.