Fixed missing break in switch case
Added a basic test and fixed some bugs