Added checks for trailing and leading spaces in input