Implement third feature, fix some bugs, refactor considerably