Refactored and cleanup