Fixed single end bug, thanks to Georgios Marnellos.