some fixes, code cleanup