Updated with Phil's latest changes