fix bug with endings