added update frequency option, fixed out of range array error, refactored