Several small code improvements