Tests

adding tests and some bugfixes to main