Finished main functionality, refactoring and
unicode support coming next.