code cleanup and api backwards compat