working version

working version but still need tuning to reduce response time