Refactor much. Add resource types.