added analytics
fixed sql issue