refactor more, fix events slightly