Removed some log print and changed them to return error out of func instead