Added tests, moved some functions into module.exports