moved code to terragen.js file