add -O2, -Wall and -Werror to CFLAGS, fix warnings in code