Code refactoring. It should be more clear now. Also, column 'type' was added in file table to prevent file type checking with slow methods every time before show or edit.