finally got it to port to r