added trim to getFirstValidOption function