Fixes, improvements, code reformat