moved setinterval to function
Fixes #2. Replaced calls to date