clean up, add policy checking and tests