code cleanup and corrections

code cleanup and corrections