fixing bugs with previous performance improvement