added more inner function checks