code cleanup, fix tests, add 'change' event support