Factor ahj view

Removes a lot of duplicate code, cleans up the template so that it easier to read and modify.