Fixed nxtapt logic to use database