more fixing of #151 and code cleanup