some fixes and reorderings