move pg routines to seperate module