Start to refactor the code

I don't intend to make anything really polished, but it'd be nice to at
least get the code to a presentable state and add ignore pattern
functionality to this.