scan word function modified