Fix build errors and warnings