Further progress!

Moved repetitive code to jinja template, and refactored input. Probably
will refactor input again, because I am not happy with it.