refactor of doubleclick code to work with external variable