Several small fixes and cleanup