Refactored and added more common code