Fix some minor issues and improve the code.