code stopps after using a function