Some fixes, mainly cleanup and easier debugging