restructure and fix tests