Fixed some bugs
Added better tests