refactored and repackaged