Refactor code somewhat, and get it to compile.