tested and fixed some errors