improvements working with database
fixes and improvements