add anlytics and clean up code