fixed having the second method to check and made one recursive function.