moved preventdefault to the right place