Code improvements and cleanup.