Cleanup file handler and fix bug (delete vs. rename).