Added 'end' event & corrected following bugs.