Adding tests and fixing behaviour