added exit code in function and removed success/error messages outside functions