added trim before empty check