Fix various errors. Declare prototypes for functions.