reduce sql statements, rework as per comment from @eve-seat