have you looked at using the application.api_* calls for things like this?