Fix various code errors/warnings
Including maybe the one mentioned #2