Create tables correctly and many other fixes