add analytics
add some tests. refactor.