Various fixes and improvements

see #376 and #379