Rewrite for API 6.0+ compatibility