adapted such that it can run within web service