function passed to setInterval needs to be in a closure

also changed timeout to 50 on recommendation and fixed some misc js style issues