Fix bugs and normalise log output