few tweaks, more stable version