really fix space bug, better code style, graceful handling of missing files, better logging