removed newlines, trailing white spaces and added check for empty lines