Added proper disposing of resources. Added compatibility for renamed files.