working code through the second to last part