added some return statements to be exit function when error happend.
added access validation