fix #89: DRY and simpler checks, some formatting in the header