rewrite i re wrote some portions and fixed a table issue