added frequency comparison, some refactoring (thanks to zach@hackerschool.com for suggestions)