Made process independent of newlines, improvements are still needed though