various fixes, improvments and cleanups