code cleanup & small fixes