Added click outside to hide and made hide modular