Refactor and improve File Manager Code