Improved test code, and finished section 5