Updated with latest tweaks from master