added some fixes
merged with iakovenko changes