a few tweaks and possible speed improvements