Moved serial functions to the top of the file.