Refactor to use rdd