Fixes from Alexey Loginov