Small code improvements and cleanup