Added RRs to arrays
Completed debug function
Added freeing of items in array when needed
Initialised flags
Removed debug code