Fixing small errors from last commit

Further testing found errors in those files, they now work properly,
added basic tests to tests.sql (must be verified visually)