added some checkings, minor fixes