more improvements, refactored common code,