Test + fixes to the logic