Fix some minor bugs and error messages