Memory & optimization & exceptional cases

Deliverance from memory leaks; code optimization; processing of
exceptional cases.