Tests and code fixed