code cleanup and upgrade to 1.6