Added on forms close functionality.

Needs testing for closing first window.