One more optimization and a bug fix