Refactored the form discovery utilities