misc fixes, putting in better comments, implementing template choosing for pages