Tests and bug fixing