fixed the first if clause so it could recognise newline