bug fixes, speed and memory improvements