replaced substr with trim
remove needless check