Refactor get available fields and add get viewable relations