Write tests for and fix compiler