moved the last remaining db query to subs.
Signed-off-by:Thorsten Eurich <thorsten@eurich.de>