Implement terminate/2 and remove logging