rewrite with working database and partly functional gui