fixed bug array indexing in event handler