refactored and cleanup;