Rewrote to use onload event listeners (closes #6).