fix errors and add a test