improve db access
fix bug