refactor a bit to avoid duplicated mouseUp