fixed exit function for javascript