Updated to compile with c99 standard and more error checking.