Re-factored and added ability to be used from GWT application.