added Some minor optimizations and cooments