some speed and memory improvements