ported base scripts form R2