Fix minor bugs and exceptions.