Fix various warnings

Fix various (potentially quite bad) warnings and normalize style.