refactor code for index and ofc