Code improvements and minor changes