Tests

Tests and bug fixes.