Updated with changes from production code