added proper table prefix support and made some variables more verbose