refactored timer setInterval for functional progamming