debugin code and fix errors