Reorganization of code.
Bugfix for delete entity. Now all files connected are deleted when deleting entity.