Fixed some misplaced {$ENDIF} calls which meant some operations were removed in a RELEASE build