Added errors to foreign functions and environments