Some code cleanup and partial implementation of Steps 8 and 9. Still not working.