use return instead of exit inside function