Minor code cleanup and fixes