cherrypicked from css refactoring