many improvements for stability and proper behavior