Style cleanup + some basic error fixing