Improved javascript using parseJSON