Generate width, height parameters in the header.

Also some re-factoring.