Changed listening function to ping api server until fulfilling sync request after regaining access
renamed variables and moved variable location to comply with more universal js standards
Implemented a counter to track failed attempts to stop after 5 attempts.