Code clean and performance improvements