cleanup and bug fixes