Fix mistakes and complete tests