implemented a test and fixed bugs so that it works