rewritten for Nodejs