Fixed possible bugs