Fixed a number of issues (printing, files without trailing newline etc.)