implemented a check to avoid eventhandlers being executed twice.