fixed bugs and wrote sql statements, this is the first working version