Restructure and add tests