fix cors issue
fix chart, add correct url
remove foreach loop
refactoring of the code, needs improvement