cleaning code; transfer to a new r file