debugging and fixing function issues

debugging and fixing function issues