Fixed bug in file new lines and refactored the code again.
Added test for fixed bug.