Various small fixes, cleanup and TODOs.