fixed some cirtical bugs