Minor code improvements and fixes