Fixed a bunch of errors and embarrasing $this instead of $table

please don't notice senpai