Cleaned up code, re-ran all tests, ready for review.