updated element id logic and added mouse up outside event handling