Code improvement and style throughout