refactored to be more compatible with cms