refactored with master corrections