Changed code to take advantage of REST API