added goal function file and made error handling nicer