refactorered parseing data code in js