Bug fixes and draft tests