Tweak admin templates and reorganize code