Tests and one bugfix