adding code to ignore final new line