Add setTimeout to ensure that session variable on server is always up to date, clean up debug statements