Main code rev. 1713

Fixed some major bugs in ERM Main record deletion