fixed the high cpu usage bug (removed array.indexOf() calls)