fixed #566, fixed #319, fixed #578, fix maybe for #572?