Refactored ifs and use readlink -f to get abs path