Fix C89 compliance and clean up code