duplicate & extra space issue resolution