moved prevent default to end of function