Fix some performance issues and a possible overflow