better code organazation, add mocha tests