few fixes and opt