db code cleaned up