added rest array function and refactored index