start of heavy rewrite to be more Node style