Tests

Bug fixes and Tests.