Fix several errors and warnings