Converted echos to fwrite for consistency