error checking and moved apriori to server