Fix some bugs. Test now pass