refactored and cleanup