refactored code. need to get settimeout to work